home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5744 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Urgent help needed
  5. Date: Tue, 06 Feb 1996 18:04:20 +0200
  6. Organization: Carelcomp Forest
  7. Message-ID: <31177C04.741C@cmt.lpr.mail.carel.fi>
  8. References: <4f6v9o$ov6@otis.netspace.net.au>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6a (WinNT; I)
  14.  
  15. Patrick Liang wrote:
  16. > I am doing a program to convert a serial no to date format, the serial no is
  17. > representing the seconds elapsed since 01/01/1970. and I using the Visual basic
  18. > to call the DLL function(general from Borland C++ version 4).
  19. > It seems there is no problem to creat the DLL in c
  20. > program, no error message, but when I run the visual basic program which call the
  21. > DLL that I created, it generate the GPF(general protection fault).  the following
  22. > is the program code.
  23. > Please help .  Thank you.
  24. > /*  This is the def file in C Using Borland C++ */
  25. > LIBRARY TEST3
  26. > DESCRIPTION  "just testing"
  27. > EXETYPE WINDOWS
  28. > CODE    PRELOAD MOVEABLE DISCARDABLE
  29. > DATA    PRELOAD MOVEABLE SINGLE
  30. > HEAPSIZE  4096
  31. > EXPORTS NUMTODATE
  32. > /*  this is the main c program Using Borland C++ */
  33. > /* Demonstrates the functions */
  34. > #include <stdio.h>
  35. > #include <time.h>
  36. > #include <stdlib.h>
  37. > #include <windows.h>
  38. > char FAR PASCAL NUMTODATE(char *argv1)
  39. > {
  40. >         struct tm *ptr;
  41. >         char *c, buf1[80];
  42. >         long l;
  43. >          l = atol(argv1);
  44. >          ptr = localtime(&l);
  45. >         c = asctime(ptr);
  46. >         puts(c);
  47. >         return *c;
  48. > }
  49. > /*  this is the visual basic program */
  50. > Declare Function NUMTODATE Lib "c:\test3.dll" (ByVal DateNum As String) As String
  51. > MsgRtn = NUMTODATE(CodeInquire)
  52. > =============================
  53.  
  54. In C code, you don't have strings; you have pointers. Also, C tends to use ASCIIZ strings (ie. 
  55. the characters of the 'string' followed by a byte that has a zero value) while in Basic, the 
  56. strings are constructed something like <length><characters>. You could declare the parameter as 
  57. a pointer and select which one of your routines is to handle it (C handling <length><characters> 
  58. strings, or Basic handling <characters><null-byte> strings). Remember to take into account the 
  59. memory model; pointers are handled differently in different models.
  60.  
  61. Later,
  62.  AriL
  63. -- 
  64. All my opinions are mine and mine alone.
  65.